function S = PSWM_InformationContent(M,B)

% S = PSWM_InformationContent(M,B)
%
% Information content for a PSWM.
% M - Motif model.
% B - 0:th order Markovian background model

% Re-normalize just in case...
M = M./(ones(4,1)*sum(M,1));
B = B./(sum(B,2)*ones(1,4));

[i,j] = size(B);
if i~=1 | j~=4
  disp('0:th order Markov background is assumed.');
  S = [];
  return;
end
if length(find(B==0))>0
  disp('Background probabilities are assumed to be nonzero.');
  S = [];
  return;
end

S = 0;
for i=1:size(M,2)
  for j=1:4
    if M(j,i)~=0
      S = S + M(j,i)*log2(M(j,i)/B(j));
    end
  end
end

S = S/size(M,2);
